﻿#region Using References

using System.Diagnostics.CodeAnalysis;
using Beaker.Services.Locator;
using FluentAssertions;
using Microsoft.Practices.ServiceLocation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ServiceLocator = Beaker.Services.Locator.ServiceLocator;

#endregion

namespace Beaker.OpenCube.Specs.Services
{
	[ExcludeFromCodeCoverage]
	[TestClass]
	public class ServiceLocatorSpecs
	{
		[TestMethod]
		public void WhenNoServiceProvidersOrLocatorSetNullShouldBeReturned()
		{
			// arrange
			ServiceLocator.ClearLocatorProvider();

			// act
			IServiceLocator returnedLocator = ServiceLocator.Current;

			// assert
			returnedLocator.Should().Be( null );
		}

		[TestMethod]
		public void WhenNotServiceProviderIsSetServiceProviderLocatorShouldBeUsed()
		{
			// arrange
			bool called = false;
			var locator = new ManualServiceLocator();
			ServiceLocator.SetLocatorProvider( () =>
			{
				called = true;
				return locator;
			} );

			// act
			IServiceLocator returnedLocator = ServiceLocator.Current;

			// assert
			called.Should().Be( true, "LocatorProvider lamba should be called" );
			returnedLocator.Should().Be( locator );
		}
	}
}
